﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleTest
{
    class Program
    {
        static void Main(string[] args)
        {
            MyDbContext db = new MyDbContext();
            //添加
            Tests ts = new Tests()
            {
                Name = "云宝"
            };
            Console.WriteLine(db.Entry(ts).State);//Detach
            db.Tests.Add(ts);
            Console.WriteLine(db.Entry(ts).State);//Added
            int num = db.SaveChanges();
            if (num>0) {
                Console.WriteLine("成功");
            }
            Console.WriteLine(db.Entry(ts).State);//Unchanged 

            //修改
            //Tests st= db.Tests.Find(2);
            //st.Name = "珍奇";
            //int result= db.SaveChanges();
            //if (result>0)
            //{
            //    Console.WriteLine("ok");
            //}

            //删除
            //Tests st= db.Tests.Find(2);
            //db.Tests.Remove(st);
            //int reuslt= db.SaveChanges();
            //if (reuslt>0)
            //{
            //     Console.WriteLine("ok");
            // }

            List<Tests> list = db.Tests.ToList();
            foreach (Tests item in list)
            {
                Console.WriteLine(item.Id + ":" + item.Name);
            }
        }
    }
}
